package day10.udp;

import java.io.IOException;
import java.net.DatagramPacket;
import java.net.DatagramSocket;

public class Server {
	public static void main(String[] args) throws IOException {
		//创建server套接字
		DatagramSocket ds = new DatagramSocket(6666);
		
		byte[] b = new byte[1024];
		//创建报文对象
		DatagramPacket dp = new DatagramPacket(b, b.length);
		
		//调用receive方法
		ds.receive(dp);
		
		//转化为字符显示
		String str = new String(b,0,dp.getLength());
		System.out.println("主机ip为:" + str);
		System.out.println("端口号为:" + dp.getPort());
		
		//关闭 通常是不关闭的
		ds.close();
	}
}
